package com.arpa.ntocc.common.service.impl;

import cn.hutool.core.util.IdUtil;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.ntocc.common.domain.dto.ResourceColDTO;
import com.arpa.ntocc.common.domain.entity.ResourceCol;
import com.arpa.ntocc.common.domain.vo.ResourceColVO;
import com.arpa.ntocc.common.mapper.ResourceColMapper;
import com.arpa.ntocc.common.service.IResourceColService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜单列表字段 服务实现类
 * </p>
 *
 * @author liuyj
 * @since 2019-11-25
 */
@Service
public class ResourceColServiceImpl extends ServiceImpl<ResourceColMapper, ResourceCol> implements IResourceColService {

    /**
     * 保存
     * @param entity
     * @return
     */
    @Override
    public boolean save(ResourceCol entity) {
        if(StringUtils.isBlank(entity.getCode())){
            entity.setCode(IdUtil.simpleUUID());
        }
        if(StringUtils.isBlank(entity.getCreatedBy())){
            entity.setCreatedBy(UserUtil.getCode());
        }
        return super.save(entity);
    }

    /**
     * 根据code更新实体
     * @param entity
     * @return
     */
    @Override
    public int updateByCode(ResourceCol entity) {
        if(StringUtils.isBlank(entity.getModifiedBy())){
            entity.setModifiedBy(UserUtil.getCode());
        }
        return baseMapper.update(entity,new QueryWrapper<ResourceCol>().lambda().eq(ResourceCol::getCode,entity.getCode()));
    }

    /**
     * 查询列表
     * @param resourceColDTO
     * @return
     */
    @Override
    public List<ResourceColVO> queryList(ResourceColDTO resourceColDTO){
        List<ResourceColVO> resourceColVOList = baseMapper.queryList(resourceColDTO);
        return resourceColVOList;
    }

    /**
     * 查询合计,包含总数
     * @param resourceColDTO
     * @return
     */
    @Override
    public ResourceColVO queryListSum(ResourceColDTO resourceColDTO){
        ResourceColVO resourceColVO = baseMapper.queryListSum(resourceColDTO);
        return resourceColVO;
    }

}
